// pages/editor/editor.js
 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths: '',
    checked1:' ',
    checked2: ' ',
    checked3: ' ',
    checked4: ' ',
    usersmsg:'',
    head:'',
    items: [
      { name: 'USA', value: '男' },
      { name: 'CHN', value: '女', checked: 'true' },
    ],
    // publics: [
    //   { name: 'USA', value: '公开', checked: 'true'},
    // ]
  },
  chooseimage: function () {
    var _this = this;
    wx.chooseImage({
      count: 1, // 默认9 
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有 
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有 
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片 
        _this.setData({
          tempFilePaths: res.tempFilePaths
        })
      }
    })
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  // start_save:function(){
  //   wx.showToast({
  //     title: '提交成功',
  //     icon: 'success',
  //     duration: 2000
  //   })
  // },
  submit:function(e){
    var that = this;
    var xingming = e.detail.value.xingming;
    var sex = e.detail.value.radio1;
    var school = e.detail.value.school;
    var email = e.detail.value.email;
    var phone = e.detail.value.phone;
    var weixin = e.detail.value.weixin;
    var qq = e.detail.value.qq;
    var sign = e.detail.value.sign;
    var self_introduction = e.detail.value.self_introduction;
    var usid = wx.getStorageSync('usid');
    var recommend = e.detail.value.recommend;
    if (xingming == "" || school == "" || email == "" || phone == "" || weixin == "" || qq == "" ) {
      wx.showToast({
        title: '请完善信息',
        icon: 'none',
        duration: 1500
      })
      return false;
    } else if (!(/^[1][3|4|5|7|8][0-9]{9}$/.test(phone))) {
      wx.showToast({
        title: '手机号有误！',
        icon: 'none',
        duration: 1500
      })
      return false;    
    }else {
      wx.request({
        url: 'https://www.135k.com/addons/sd_humans/tp/index.php/users/editinfo',
        data: {
          usid: usid,
          name:xingming,
          sex:sex,
          school:school,
          phone:phone,
          email:email,
          vx:weixin,
          qq:qq,
          sign:sign,
          self_introduction: self_introduction,
          recommend: recommend
        },
        method: "post",
        dataType: "json",
        success: function (res) {
          that.setData({
            usersmsg: res.data.list,
          });
          wx.showToast({
            title: '修改成功',
            icon: 'success',
            duration: 1500
          })
          setTimeout(function () {//确认之后跳转的页面
            wx.navigateTo({
              url: '../info/info'
            })
          }, 1500);
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      head:wx.getStorageSync('head')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    let usid = wx.getStorageSync('usid');
    let uid  = wx.getStorageSync('uid');
    if (usid == '') {
      wx.request({
        url: 'https://www.135k.com/addons/sd_humans/tp/index.php/users/userinfo',
        data: {
          uid: uid
        },
        method: "post",
        success: function (res) {
          wx.setStorageSync("usid", res.data[0].uid);
        }
      })
    } else {
      wx.request({
        url: 'https://www.135k.com/addons/sd_humans/tp/index.php/users/getinfo',
        data: {
          usid: usid
        },
        method: "post",
        dataType: "json",
        success: function (res) {
          if (res.data.list.sex == '男') {
            that.setData({
              usersmsg: res.data.list,
              items: [
                { name: 'USA', value: '男', checked: 'true' },
                { name: 'CHN', value: '女' },
              ]
            })
          } else {
            that.setData({
              usersmsg: res.data.list,
              items: [
                { name: 'USA', value: '男' },
                { name: 'CHN', value: '女', checked: 'true' },
              ]
            })
          }
          console.log(that.data.usersmsg, 'uuuusid');
        }
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})